Project's aim is to extend Zend Framework with new PDF functionality.
PHProjekt_Pdf is a library for creating PDF documents with tables. Library uses Zend framework  functionality for PDF documents and
provides with additional not implemeted functions for drawing tables together with free text.
User can choose the position of the element and add some additional properties to the text and table decoration.

Autor: Alesia Khizhko <alesia.khizhko@mayflower.de>

Document contain more detailed information about Phprojekt_Pdf_Page usage, particulary parseTemplate() function.

Content.
1. Param of the function Phprojekt_Pdf_Page::parseTemplate() .
1.1. Specification of table element.
1.2. Specification of Free text  element.

2. Example of usage.
3. Known bugs.


1. Param of the function Phprojekt_Pdf_Page::parseTemplate() .

Template has a form of array, where some fields have specific form.

Fields are:
1.Elements to parse.
2.font     - (optional) type of string, contain the name of the font
3.fontSize - (optional) type of int, contain font size

For example:

array(
    0 => array(....),
    1 => array(....),
        ...

    'font'     => 'Helvetica',
    'fontSize' => 10
);

Each element for parsing is an array. There are 2 types of elements.

1.1. Specification of table in $template.

Array of element should contain following keys:

type - with value 'table', which defines a type of the element
rows - value is an array, where every row contain array of columns

Optional parameters are:
startX and startY  - (optional) values of type int, define coordinates of left top corner of the table.
                     By default element would be added to the next free line in the document.
fontSize  - (optional) change font size for the free text
lineWidth - (optional) change width of lines for the free text

For example:

array('type'   => 'table',
      'startX' => 35,
      'startY' => 160,
      'rows'   => array(
          array(...array of columns...),
          array(...array of columns...))
)

Column has type of array with following rows:
1.text      - type of text
2.width     - type of int, width of the column
3.alignment - (optional) type of string, left is by default

Text would be parsed according to the cell width, keeping all passed paragraphs

For example:
array('text' => 'Datum', 'width' => 50);

There is a possibility to mark header with background grey color. To use it user need to pass
'isHeader' => true
to the seleceted row.

For example:
'rows' => array(
    array(
        'isHeader' => true,
        array('text' => 'Datum ', 'width' => 100),
        array('text' => '06.05.2009', 'width' => 150)),
    array(
        array('text' => 'Naechster Termin', 'width' => 100),
        array('text' => '12.05.2009', 'width' => 150)),
)

1.2. Specification of Free text in $template.

Array of element should contain following keys:
type  - with a value 'freetext', which defines a type of the element,
lines - value is array of strings or text, where every string would be inserted from the new line, saving paragraphs

Optional parameters are:
startX and startY - (optional) values of type int, define coordinates of left top corner of the Free text block
                     By default element would be added to the next free line in the document.
fontSize  - (optional) change font size for the free text
lineWidth - (optional) change width of lines for the free text
width     - (optional) width of the free text

For example:

array(
     'type'      => 'freetext',
     'startX'    => 35,
     'startY'    => 140,
     'lineWidth' => 0.5,
     'fontSize'  => 12,
     'lines'     => array('First line free text', 'Second line free text')
)

2. Example of usage.
2.1 Default settings

<?php
$pdf  = new Zend_Pdf();
$page = new Phprojekt_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER);

$template = array(
    0 => array(
        'type' => 'table',
        'rows' => array(
            array(
                array('text' => 'Datum', 'width' => 50),
                array('text' => '06.05.2009', 'width' => 150),
                array('text' => 'Naechster Termin', 'width' => 100),
                array('text' => '12.05.2009', 'width' => 100)),
            array(
                array('text' => 'Datum', 'width' => 50),
                array('text' => '12.05.2009', 'width' => 150),
                array('text' => 'Naechster Termin', 'width' => 100),
                array('text' => '15.05.2009', 'width' => 100)),
        )
    ),
    1 => array(
        'type' => 'table',
        'rows' => array(
            array(
                array('text' => 'Datum', 'width' => 50),
                array('text' => '06.05.2009', 'width' => 150)),
            array(
                array('text' => 'Naechster Termin', 'width' => 50),
                array('text' => '12.05.2009', 'width' => 150)),
        )
    ),
    2 => array(
        'type' => 'freetext',
        'lines' => array('First line free text', 'Second line free text')
    )
);

$pages = $page->parseTemplate($template);

$pdf->pages[] = $page;
foreach ($pages as $page) {
    $pdf->pages[] = $page;
}

$pdf->save('Testname.pdf');
?>



2.2 With some additional properties.
<?php
$pdf  = new Zend_Pdf();
$page = new Phprojekt_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER);

$template = array(
    'font'     => 'Helvetica',
    'fontSize' => 10,
    0 => array(
        'type' => 'table',
        'rows' => array(
            array(
                array('text' => 'Datum', 'width' => 50, 'align' => 'center'),
                array('text' => '06.05.2009', 'width' => 150),
                array('text' => 'Naechster Termin', 'width' => 100),
                array('text' => '12.05.2009', 'width' => 100)),
            array(
                array('text' => 'Datum', 'width' => 50, 'align' => 'right'),
                array('text' => '12.05.2009', 'width' => 150),
                array('text' => 'Naechster Termin', 'width' => 100),
                array('text' => '15.05.2009', 'width' => 100)),
        )
    ),
    1 => array(
        'type'   => 'table',
        'startX' => 35,
        'startY' => 160,
        'rows'   => array(
            array(
                array('text' => 'Datum', 'width' => 50),
                array('text' => '06.05.2009', 'width' => 150)),
            array(
                array('text' => 'Naechster Termin', 'width' => 50),
                array('text' => '12.05.2009', 'width' => 150)),
        )
    ),
    2 => array(
        'type'      => 'freetext',
        'startX'    => 35,
        'startY'    => 140,
        'lineWidth' => 0.5,
        'fontSize'  => 12,
        'lines'     => array('First line free text', 'Second line free text')
    )
);

$pages = $page->parseTemplate($template);

$pdf->pages[] = $page;
foreach ($pages as $page) {
    $pdf->pages[] = $page;
}

$pdf->save('Testname.pdf');
?>


This code would create test pdf file with 2 tables, free text with 2 lines.
3. Known bugs

- Library works incorrect in case one of the cells has an inner text which after parsing can't in current page fit.
- Library don't care about overlapping of the elements and width of elements. For example when the user passed to prototype free text element with
fixed coordinates, library wouldn't check if element would fit to the page with width. In case element is bigger than the page,
it would be printed as long as it's possible. In case given position of the element is not free, elements will overlap.
